const path = require('path')
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import styleImport from 'vite-plugin-style-import';

// https://vitejs.dev/config/
export default defineConfig(env => {
  return {
    plugins: [
      vue(),
      styleImport({
        libs: [{
          libraryName: 'ant-design-vue',
          esModule: true,
          resolveStyle: (name) => {
            return `ant-design-vue/es/${name}/style/css`;
          },
        }]
      })
    ],
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "src"),
      }
    },
    css: {
      preprocessorOptions: {
        less: {
          javascriptEnabled: true,
        }
      }
    },
    optimizeDeps: {
      include: ["@ant-design/icons-vue"],
    },

    build: {
      lib: {
        name: 'IvzOnline',
        formats: ["es", "umd"],
        entry: path.resolve(__dirname, 'src/lib/index.js')
      },
      cssCodeSplit: true,
      sourcemap: true,
      rollupOptions: {
        // 请确保外部化那些你的库中不需要的依赖
        external: ['vue', 'ant-design-vue', 'vuex', 'vue-router'],
        output: {
          // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
          globals: {
            vue: 'Vue',
            'vuex': 'Vuex',
            'vue-router': 'VueRouter',
            'ant-design-vue': 'Antd',
            'ant-design-vue/dist/antd.css': ''
          }
        }
      }
    }
  }
})
